package arg

import (
	"encoding/json"
	"errors"
	"fmt"
	"db2s/global"
	"reflect"
	"strings"
)

type metricsLimit struct {
}
type limitLevel struct {
	Switch  bool         `json:"switch"`
	Metrics metricsLimit `json:"metrics"`
}
type limitMode struct {
	Cpu  reflect.Value `json:"cpu"`
	Mem  reflect.Value `json:"mem"`
	Net  reflect.Value `json:"net"`
	Disk reflect.Value `json:"disk"`
}

// rulesSecondaryLevelParameterCheck
func (rc *ConfigParameter) limitSecondaryLevelParameter() error {
	var (
		s2 []string
	)
	if r, err := global.StructToMapAny(getLimit()); err != nil {
		return err
	} else {
		for k, v := range r {
			if r1 := rc.getHoconConfigVal(rc.FirstL1.Limit.ToConfig(), k, reflect.TypeOf(v).String()); r1 != nil && r1 != 0 {
				s2 = append(s2, rc.anyToJsonString(k, r1))
			} else {
				s2 = append(s2, rc.anyToJsonString(k, v))
			}
		}
	}
	jsonData := fmt.Sprintf("{%s}", strings.Join(s2, ","))
	if err := json.Unmarshal([]byte(jsonData), &rc.SecondaryL.RulesV); err != nil {
		vlog := fmt.Sprintf("(%d) %s rule parameter init fail. json unmarshal fail error info is %s. json data is {%s}", rc.LogThreadSeq, rc.event, err, jsonData)
		WLog.Error(vlog)
		err = errors.New(fmt.Sprintf("rule parameter json unmarshal fail,please check the log for details!"))
		return err
	}
	//if err := rc.checkModGet(); err != nil {
	//	return err
	//}
	return nil
}
